package top.xiaoazi.futureletterserver.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.xiaoazi.futureletterserver.interceptor.*;

/**
 * 拦截器的配置
 */
@Configuration
public class AppConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Autowired
    private VerifyCodeListDataInterceptor verifyCodeListDataInterceptor; // 验证码模块扫尾工作

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/user/*")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/system-reg")
                .excludePathPatterns("/user/reg")
                .excludePathPatterns("/user/generate-email-code")
                .excludePathPatterns("/user/test")
                .excludePathPatterns("/user/is-login");

        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/letter/*")
                .excludePathPatterns("/letter/submit-bug")  // 用户反馈 bug 接口, 排除需要登录
                .excludePathPatterns("/letter/get-waiting-send-count") // 排除待发送信件统计, 前端主页展示用
                .excludePathPatterns("/letter/get-sent-count");  // 排除发送信件的统计信息, 前端主页展示用

    }

}
